package com.task.netty.util;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.pingpang.common.bean.RequestBean;
import com.pingpang.common.bean.ResponseBean;
import com.pingpang.netty.client.NettyClient;
import com.task.bean.TaskRunBean;

/**
  * 请求工具类
 * @author Soap0
 */
@Component
public class ClientRequest {

  private Logger log=LoggerFactory.getLogger(ClientRequest.class);
  @Autowired
  private NettyClient nettyClient; 
  
  public  ResponseBean SendMsg(TaskRunBean tb) throws InterruptedException, IOException {
	  log.info("---任务调度开始---");
	  log.info("---IP端口:"+tb.getRegistIPPort());
	  log.info("---类:"+tb.getRegistName());
	  log.info("---方法:"+tb.getRegistMethod());
	  String ipPort[]=tb.getRegistIPPort().split(":",-1);
	  RequestBean request = new RequestBean();
      request.setClassName(tb.getRegistName());
      request.setMethodName(tb.getRegistMethod());
      request.setParameters(null);
      request.setParameterTypes(null);
      request.setIp(ipPort[0]);
      request.setPort(Integer.valueOf(ipPort[1]));
      request.setId("1");
      Object result = nettyClient.send(request);
      ResponseBean response =(ResponseBean)result;
      log.info("---返回代码:"+response.getCode());
      log.info("---返回信息:"+response.getErrorMsg());
      log.info("---任务调度结束---");
      //nettyClient.destroy();
      return response;
      //Object data = response.getData();
      //System.out.println(data.toString());
  }
}
